package com.lw.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lw.system.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    @Select( "select * from role where id in (select role_id from users_role where user_id =#{id})" )
    @Results({
            @Result(property = "id",id = true,column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "description",column = "description"),
            @Result(property = "companyId",column = "company_id"),
            @Result(property = "permissions",column = "id",javaType = java.util.List.class,many = @Many(select = "com.lw.mapper.PermissionMapper.findById"))
    })
    List<Role> findById(String id);
    @Select( "select * from role ${ew.customSqlSegment}" )
    @Results({
            @Result(id = true,property ="id",column = "id"),
            @Result(property ="name",column = "name"),
            @Result(property ="description",column = "description"),
            @Result(property ="companyId",column = "company_id"),
            @Result(property = "permissions",column = "id",many = @Many(select = "com.lw.mapper.PermissionMapper.findById"))
    })
    Page<Role> findAll(Page<Role> page, QueryWrapper ew);
}
